package api

import (
	"dy/internal/api/controller/comment"
	"dy/internal/api/controller/favorite"
	"dy/internal/api/controller/message"
	"dy/internal/api/controller/relation"
	"dy/internal/api/controller/user"
	"dy/internal/api/controller/video"
	"dy/internal/api/store"
	"net/http"

	"github.com/gin-gonic/gin"
)

func RouterInit() *gin.Engine {
	router := gin.Default()
	router.Use(gin.Logger())
	router.Use(gin.Recovery())
	mysqlStore, _ := store.GetFactory()
	apiRouter := router.Group("/douyin")

	videoController := video.NewVideoController(mysqlStore)
	commentController := comment.NewCommentController(mysqlStore)
	favoriteController := favorite.NewFavoriteController(mysqlStore)
	messageController := message.NewMessageController(mysqlStore)
	relationController := relation.NewRelationController(mysqlStore)
	userController := user.NewUserController(mysqlStore)

	//basic
	apiRouter.GET("/feed/", videoController.Feed)

	apiRouter.GET("/user/", userController.UserInfo)
	apiRouter.POST("/user/register/", userController.Register)
	apiRouter.POST("/user/login/", userController.Login)

	apiRouter.POST("/publish/action/", videoController.PublishAction)
	apiRouter.GET("/publish/list/", videoController.PublishList)

	apiRouter.POST("/favorite/action/", favoriteController.FavoriteAction)
	apiRouter.GET("/favorite/list/", favoriteController.FavoriteList)

	apiRouter.POST("/comment/action/", commentController.CommentAction)
	apiRouter.GET("/comment/list/", commentController.CommentList)

	apiRouter.POST("/relation/action/", relationController.RelationAction)
	apiRouter.GET("/relation/follow/list/", relationController.FollowList)
	apiRouter.GET("/relation/follower/list/", relationController.FollowerList)
	apiRouter.GET("/relation/friend/list/", relationController.FriendList)

	apiRouter.GET("/message/chat/", messageController.MessageChat)
	apiRouter.POST("/message/action/", messageController.MessageAction)
	apiRouter.StaticFS("/buffer", http.Dir("/home/ubuntu/Project/dy-demo/buffer"))
	return router
}

// 101.42.1.46:8079/douyin/buffer/video/6_mmexport1674726263690.mp4
// 101.42.1.46:8079/douyin/buffer/cover/Snipaste_2023-02-19_20-30-25.png
